package com.chat.gateway.filter;

import org.springframework.cloud.gateway.filter.GatewayFilter;
import org.springframework.cloud.gateway.filter.GatewayFilterChain;
import org.springframework.core.Ordered;
import org.springframework.core.annotation.Order;
import org.springframework.web.server.ServerWebExchange;
import reactor.core.publisher.Mono;

import java.lang.annotation.Annotation;

public class TestFilter implements GatewayFilter, Ordered {

    @Override
    public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
        String hostString = exchange.getRequest().getRemoteAddress().getHostString();
        System.out.println(exchange.getRequest().getQueryParams().get("userName"));
        System.out.println("过滤地址:" + hostString + ";方法路径:" + exchange.getRequest().getPath());
        //执行完当前过滤器继续执行
        return chain.filter(exchange);
        //直接返回结果
//        exchange.getResponse().setStatusCode(HttpStatus.UNAUTHORIZED);
//        return exchange.getResponse().setComplete();
    }


    //优先级
    @Override
    public int getOrder() {
        return 0;
    }
}
